<?php
include($_SERVER['DOCUMENT_ROOT'] . "/admin/includes/interceptor.php");
require_once($_SERVER['DOCUMENT_ROOT'] . '/static/db/connect.php');
$sql = " select id,name,img,outline,win,mac,all_ver,version,win_version,sort from qt_software_box ORDER BY sort DESC ";
$mysqli_result = $mysqli->query($sql);
if ($mysqli_result && $mysqli_result->num_rows > 0) {
    while ($row = $mysqli_result->fetch_assoc()) {
        $rows[] = $row;
    }
}
$mysqli_result->close();
$mysqli->close();

?>
<style>
    .btn-mine {
        background-color: #ffffff;
        border-color: #ffffff;
        color: #000;
    }
</style>
<script>
    function add() {
        $('#addData').attr("src", "/admin/view/software/addData.php");
        $('#myModal').modal({});
    }

    function edit(id) {
        alert('暂不支持编辑');
    }

    function del(id) {
        $.post("/admin/view/software/listDel.php", {'id': id}, function (res) {
            if (res == 1) {
                setTimeout(function () {
                    closeModal();
                }, 1000);
            }
        });
    }

    function closeModal() {
        $('#myModal').modal('hide');
        setTimeout(function () {
            loadMain("/admin/view/software/softwareList.php");
        }, 100);
    }
</script>
<div class="row">
    <div class="col-lg-12">
        <section class="panel">
            <header class="panel-heading">
                软件列表
                <button type='button' class='btn btn-info btn-mine btn-sm' onclick='add();'><i class='icon-plus'></i>
                </button>
            </header>
            <table class="table table-striped table-advance table-hover table-bordered" id="dataTable">
                <thead>
                <tr>
                    <th class="hidden-phone" width="50px">ID</th>
                    <th width="200px"><i class="icon-bullhorn"></i> 标题</th>
                    <th><i class="icon-book"></i> 简介</th>
                    <th class="hidden-phone" width="100px"><i class="icon-question-sign"></i> MAC版本</th>
                    <th class="hidden-phone" width="100px"><i class="icon-bookmark"></i> Win版本</th>
                    <th width="80px">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($rows as $row): ?>
                    <!--                    id,name,img,outline,win,mac,all_ver,version,win_version,sort-->
                    <tr>
                        <td class="hidden-phone"><?php echo $row['id']; ?></td>
                        <td><a href="#"><?php echo $row['name']; ?></a></td>
                        <td><a href="#"><?php echo $row['outline']; ?></a></td>
                        <td class="hidden-phone"><?php echo $row['version']; ?></td>
                        <td class="center hidden-phone"><?php echo $row['win_version']; ?></td>
                        <td>
                            <button class="btn btn-primary btn-xs hidden-phone"
                                    onclick="edit('<?php echo $row['id'] ?>');"><i class="icon-pencil"></i></button>
                            <button class="btn btn-danger btn-xs" onclick="del('<?php echo $row['id'] ?>')"><i
                                        class="icon-trash"></i>
                            </button>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </section>
    </div>
</div>

<!--新增数据弹框-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    新增数据
                </h4>
            </div>
            <div class="modal-body">
                <iframe id="addData" width="100%" height="520px" frameborder="0"></iframe>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="/admin/static/assets/data-tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="/admin/static/assets/data-tables/DT_bootstrap.js"></script>
<!---->
<!--<script src="/admin/static/js/dynamic-table.js"></script>-->
